function showLoadingImage(id)
{
	jQuery('#' + id).html("<div class='indicator'>&nbsp;</div>");
}
function LoadAjaxPage(url, id) {
	var url = url;
	showLoadingImage(id);
	
	jQuery.get(url, function(data) {
		jQuery('#' + id).html(data);
	});
}

function reorderKeywordElement() {
	$('ul.keywordList').each(function() {
		if ($(this).hasClass('selectedKeywordList')) {
			i = 0;
			$(this).children('li').each(function() {
				$(this).children('input').removeAttr('disabled');
				$(this).children('input').attr('value', i);
				i++;
			});
		} else if ($(this).hasClass('unselectedKeywordList')) {
			$(this).children('li').each(function(i) {
				$(this).children('input').attr('disabled', 'disabled');
				$(this).children('input').attr('value', '');
			});
		}
	});
}

function updateListLive(url, pageInputId, listContId, loaderId) {
	if(is_live_loading)
	{
		return;
	}
	is_live_loading = true; // lock the loading process
	if (load_more) {
		page_num = parseInt($('#' + pageInputId).val());
		url += "/page/" + (++page_num);
		$('#' + loaderId).show();
		$.get(url, function(newitems) {
			$('#' + listContId).append(newitems);
			$('#' + loaderId).hide();
			$('#' + pageInputId).val(page_num);
			is_live_loading = false; // unlock the loading process
		});
	}
	
}

function submit_ajax_form(form_id, container_id)
{
	var f = $('#'+form_id);
	
	$('#'+ container_id).html("<div class='indicator'>&nbsp;</div>");
	$.ajax({
		url:     f.attr('action'),
		type:    f.attr('method'),
		data:    f.serialize(),
		success: function(data){
		  $('#'+container_id).html(data);
	    }
	});
}

function addLikeComplete(request, suffix)
{
	//console.log(request.status);
	if(request.status == 304)
	{
		$('#add_like_cont_'+suffix).html('<span>already liked. </span>');
	}
	else
	{
	  old_num = parseInt($('#LikeCount_'+suffix).html());
	  $('#LikeCount_'+suffix).html(old_num+1);
	}
}


function generatePopup(url)
{
	$('body').append($('<div></div>').attr({ 'id' : 'popupContainer' }));
	$("body").append($('<div></div>').attr({ 'id' : 'lightBoxContener' }));

	$('#lightBoxContener').addClass('lightBoxCont');
	$("#popupContainer").click(function(){
		closePopup();
	});

	$("#popupContainer").height(document.body.scrollHeight);
	$("#popupContainer").show();
	$("#lightBoxContener").show();

	jQuery('#lightBoxContener').html("<div class='indicator'>&nbsp;</div>");

	LoadAjaxPage(url, 'lightBoxContener');
}


function closePopup()
{
	$("#lightBoxContener").fadeOut('slow',function(){
		$(this).remove();
		$('#popupContainer').fadeOut('slow',function(){
			$(this).remove();
		});
	});
}